// 导航栏滚动效果
window.addEventListener('scroll', function() {
    const header = document.querySelector('header');
    if (window.scrollY > 50) {
        header.classList.add('bg-primary/95', 'shadow-lg');
        header.classList.remove('bg-gradient-to-r', 'from-primary/90', 'to-secondary/90');
    } else {
        header.classList.remove('bg-primary/95', 'shadow-lg');
        header.classList.add('bg-gradient-to-r', 'from-primary/90', 'to-secondary/90');
    }
});

// 平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});
document.addEventListener('DOMContentLoaded', function() {
    // 获取轮播元素
    const sliderItems = document.querySelectorAll('.slider-item');
    const prevBtn = document.querySelector('.slider-prev');
    const nextBtn = document.querySelector('.slider-next');
    const dots = document.querySelectorAll('.slider-dot');
    
    let currentSlide = 0;
    const slideCount = sliderItems.length;
    
    // 初始化轮播图
    function initSlider() {
        showSlide(currentSlide);
        
        // 设置自动轮播
        setInterval(nextSlide, 5000);
    }
    
    // 显示指定轮播项
    function showSlide(index) {
        // 隐藏所有轮播项
        sliderItems.forEach(item => {
            item.classList.add('opacity-0');
            item.classList.remove('opacity-100');
        });
        
        // 重置所有指示器
        dots.forEach(dot => {
            dot.classList.add('opacity-50');
            dot.classList.remove('opacity-100');
        });
        
        // 显示当前轮播项和激活指示器
        sliderItems[index].classList.remove('opacity-0');
        sliderItems[index].classList.add('opacity-100');
        dots[index].classList.remove('opacity-50');
        dots[index].classList.add('opacity-100');
    }
    
    // 下一张轮播图
    function nextSlide() {
        currentSlide = (currentSlide + 1) % slideCount;
        showSlide(currentSlide);
    }
    
    // 上一张轮播图
    function prevSlide() {
        currentSlide = (currentSlide - 1 + slideCount) % slideCount;
        showSlide(currentSlide);
    }
    
    // 点击事件绑定
    prevBtn.addEventListener('click', prevSlide);
    nextBtn.addEventListener('click', nextSlide);
    
    // 指示器点击事件
    dots.forEach((dot, index) => {
        dot.addEventListener('click', () => {
            currentSlide = index;
            showSlide(currentSlide);
        });
    });
    
    // 初始化轮播
    initSlider();

    // 添加点击事件处理
    sliderItems.forEach(item => {
        item.addEventListener('click', function() {
            const href = this.getAttribute('data-href');
            if (href) {
                window.location.href = href;
            }
        });
    });
});
